<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>变量和运算符 | 浪飞IT小栈</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="前后端技术分享">
    <meta name="keywords" content="前端博客,后端博客,人工智能,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown,java,Spring,Springboot,Redis,mysql">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.ada71c49.css" as="style"><link rel="preload" href="/assets/js/app.a2a00aa5.js" as="script"><link rel="preload" href="/assets/js/2.256f807a.js" as="script"><link rel="preload" href="/assets/js/14.03fc6f12.js" as="script"><link rel="prefetch" href="/assets/js/10.ab144fe3.js"><link rel="prefetch" href="/assets/js/11.062e0879.js"><link rel="prefetch" href="/assets/js/12.f9c60882.js"><link rel="prefetch" href="/assets/js/13.0a6ebfcf.js"><link rel="prefetch" href="/assets/js/15.19dbf9fd.js"><link rel="prefetch" href="/assets/js/16.6e68160b.js"><link rel="prefetch" href="/assets/js/17.1d678834.js"><link rel="prefetch" href="/assets/js/18.4536fd5c.js"><link rel="prefetch" href="/assets/js/19.9c1b65df.js"><link rel="prefetch" href="/assets/js/20.c5f96e71.js"><link rel="prefetch" href="/assets/js/21.3f0b334e.js"><link rel="prefetch" href="/assets/js/22.55c868be.js"><link rel="prefetch" href="/assets/js/23.91286241.js"><link rel="prefetch" href="/assets/js/24.c1af1909.js"><link rel="prefetch" href="/assets/js/25.a995a755.js"><link rel="prefetch" href="/assets/js/26.abc5dea3.js"><link rel="prefetch" href="/assets/js/27.1eb62850.js"><link rel="prefetch" href="/assets/js/28.b383a871.js"><link rel="prefetch" href="/assets/js/29.088e0d73.js"><link rel="prefetch" href="/assets/js/3.cd716564.js"><link rel="prefetch" href="/assets/js/30.3ccc98d5.js"><link rel="prefetch" href="/assets/js/31.aab7cc23.js"><link rel="prefetch" href="/assets/js/32.5e16b7e6.js"><link rel="prefetch" href="/assets/js/33.4aaeb741.js"><link rel="prefetch" href="/assets/js/34.45e8e898.js"><link rel="prefetch" href="/assets/js/35.5899c97a.js"><link rel="prefetch" href="/assets/js/36.32e2e263.js"><link rel="prefetch" href="/assets/js/37.c4e27bbd.js"><link rel="prefetch" href="/assets/js/38.fe5e60d2.js"><link rel="prefetch" href="/assets/js/39.2cb0b4ee.js"><link rel="prefetch" href="/assets/js/4.edf4d5e7.js"><link rel="prefetch" href="/assets/js/40.08d5bead.js"><link rel="prefetch" href="/assets/js/41.2f80f24b.js"><link rel="prefetch" href="/assets/js/42.43a49913.js"><link rel="prefetch" href="/assets/js/43.08da7ec2.js"><link rel="prefetch" href="/assets/js/44.7c7cb8a9.js"><link rel="prefetch" href="/assets/js/45.0ddf7e7f.js"><link rel="prefetch" href="/assets/js/46.7c4609a5.js"><link rel="prefetch" href="/assets/js/47.edf3ddf8.js"><link rel="prefetch" href="/assets/js/48.569a90b9.js"><link rel="prefetch" href="/assets/js/49.fa368ac8.js"><link rel="prefetch" href="/assets/js/5.24054156.js"><link rel="prefetch" href="/assets/js/50.b9b3ea7f.js"><link rel="prefetch" href="/assets/js/51.a2ebf0fe.js"><link rel="prefetch" href="/assets/js/52.31f02238.js"><link rel="prefetch" href="/assets/js/53.4110ef1e.js"><link rel="prefetch" href="/assets/js/54.dab741c7.js"><link rel="prefetch" href="/assets/js/55.f27984e9.js"><link rel="prefetch" href="/assets/js/56.bd4c1a8e.js"><link rel="prefetch" href="/assets/js/57.375d40cb.js"><link rel="prefetch" href="/assets/js/58.932e3864.js"><link rel="prefetch" href="/assets/js/59.e657be1b.js"><link rel="prefetch" href="/assets/js/6.b259c061.js"><link rel="prefetch" href="/assets/js/60.88d94274.js"><link rel="prefetch" href="/assets/js/61.fa71d884.js"><link rel="prefetch" href="/assets/js/62.a9d3b3b7.js"><link rel="prefetch" href="/assets/js/63.f849fe75.js"><link rel="prefetch" href="/assets/js/64.1770f7a9.js"><link rel="prefetch" href="/assets/js/65.6afc33db.js"><link rel="prefetch" href="/assets/js/66.799f2eb4.js"><link rel="prefetch" href="/assets/js/67.f36b2f7d.js"><link rel="prefetch" href="/assets/js/68.868cd00b.js"><link rel="prefetch" href="/assets/js/69.4c29b907.js"><link rel="prefetch" href="/assets/js/7.e34ea00f.js"><link rel="prefetch" href="/assets/js/70.1b993ed4.js"><link rel="prefetch" href="/assets/js/71.e16ad4f9.js"><link rel="prefetch" href="/assets/js/72.627505e6.js"><link rel="prefetch" href="/assets/js/73.32768e14.js"><link rel="prefetch" href="/assets/js/74.968a580d.js"><link rel="prefetch" href="/assets/js/75.42d5af3d.js"><link rel="prefetch" href="/assets/js/76.19a69d31.js"><link rel="prefetch" href="/assets/js/77.cf627a78.js"><link rel="prefetch" href="/assets/js/78.07177880.js"><link rel="prefetch" href="/assets/js/8.c4dd00ce.js"><link rel="prefetch" href="/assets/js/9.0ff73be2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ada71c49.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="浪飞IT小栈" class="logo"> <span class="site-name can-hide">浪飞IT小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/avatar.jpg"> <div class="blogger-info"><h3>浪飞yes</h3> <span>无法简单的人儿~</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开篇</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>基础语法</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/a5bdcf/" class="sidebar-link">计算机导论与环境配置</a></li><li><a href="/pages/32e9a2/" class="sidebar-link">Java开发入门与数据类型</a></li><li><a href="/pages/0ccc48/" aria-current="page" class="active sidebar-link">变量和运算符</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/0ccc48/#一、今日学习内容与目标" class="sidebar-link">一、今日学习内容与目标</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_1-1-学习内容" class="sidebar-link">1.1 学习内容</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_1-2-学习目标" class="sidebar-link">1.2 学习目标</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/0ccc48/#二、变量和运算符" class="sidebar-link">二、变量和运算符</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_2-1-数据类型-重点" class="sidebar-link">2.1 数据类型（重点）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_2-2-变量-重点" class="sidebar-link">2.2 变量（重点）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_2-2-1-变量概述-了解" class="sidebar-link">2.2.1 变量概述（了解）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_2-2-2-变量定义和赋值-重点" class="sidebar-link">2.2.2 变量定义和赋值（重点）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_2-2-3-表达式" class="sidebar-link">2.2.3 表达式</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/0ccc48/#三、基本数据类型转换" class="sidebar-link">三、基本数据类型转换</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_3-1-自动类型转换-掌握" class="sidebar-link">3.1 自动类型转换（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_3-2-自动类型提升-掌握" class="sidebar-link">3.2 自动类型提升（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_3-3-强制类型转换-掌握" class="sidebar-link">3.3 强制类型转换（掌握）</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/0ccc48/#四、运算符" class="sidebar-link">四、运算符</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_4-1-算术运算符-掌握" class="sidebar-link">4.1 算术运算符（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_4-1-1-加减乘除余-了解" class="sidebar-link">4.1.1 加减乘除余（了解）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_4-1-2-自增和自减-掌握" class="sidebar-link">4.1.2 自增和自减（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_4-2-赋值运算符-掌握" class="sidebar-link">4.2 赋值运算符（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_4-3-比较运算符-掌握" class="sidebar-link">4.3 比较运算符（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_4-4-三元运算符-掌握" class="sidebar-link">4.4 三元运算符（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_4-5-逻辑运算符-掌握" class="sidebar-link">4.5 逻辑运算符（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_4-5-1-基本使用-掌握" class="sidebar-link">4.5.1 基本使用（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/0ccc48/#_4-5-2-短路运算-掌握" class="sidebar-link">4.5.2 短路运算（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/0ccc48/#_4-6-运算优先级-了解" class="sidebar-link">4.6 运算优先级（了解）</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/0ccc48/#五、小结与作业" class="sidebar-link">五、小结与作业</a></li></ul></li><li><a href="/pages/67fd43/" class="sidebar-link">选择语句和循环语句</a></li><li><a href="/pages/92a804/" class="sidebar-link">一维数组</a></li><li><a href="/pages/0840c0/" class="sidebar-link">方法定义与使用</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>面向对象</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>常用类</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础高级</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端技术</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>热门框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前后端分离</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>权限控制</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>NoSQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>微服务</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>消息中间件</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>脚手架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>技术增值</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=Java%E9%80%9F%E9%80%9A" title="分类" data-v-06225672>Java速通</a></li><li data-v-06225672><a href="/categories/?category=%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95" title="分类" data-v-06225672>基础语法</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/langfeiyes" target="_blank" title="作者" class="beLink" data-v-06225672>langfeiyes</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-02-28</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">变量和运算符<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="变量和运算符"><a href="#变量和运算符" class="header-anchor">#</a> 变量和运算符</h1> <h2 id="一、今日学习内容与目标"><a href="#一、今日学习内容与目标" class="header-anchor">#</a> 一、今日学习内容与目标</h2> <h3 id="_1-1-学习内容"><a href="#_1-1-学习内容" class="header-anchor">#</a> 1.1 学习内容</h3> <ul><li>变量的定义和使用</li> <li>基本数据类型的转换</li> <li>算术运算符</li> <li>赋值运算符</li> <li>比较运算符</li> <li>三元运算符</li> <li>逻辑运算符</li></ul> <h3 id="_1-2-学习目标"><a href="#_1-2-学习目标" class="header-anchor">#</a> 1.2 学习目标</h3> <ul><li>必须掌握变量的定义和赋值、使用</li> <li>掌握基本数据类型的自动转换</li> <li>掌握基本数据类型的自动提升</li> <li>掌握基本数据类型的强制转换</li> <li>掌握算术运算符的使用</li> <li>了解什么是前置++和后置++的区别</li> <li>掌握赋值运算符的使用，以及它的底层含义</li> <li>掌握比较运算符的使用</li> <li>必须掌握三元运算符的语法和使用</li> <li>掌握逻辑运算符的使用（常用 &amp;&amp; 、|| 、！）</li> <li>了解与（&amp;）和短路与（&amp;&amp;）的区别，记住结论使用&amp;&amp;即可</li> <li>了解运算符的优先级</li></ul> <h2 id="二、变量和运算符"><a href="#二、变量和运算符" class="header-anchor">#</a> 二、变量和运算符</h2> <h3 id="_2-1-数据类型-重点"><a href="#_2-1-数据类型-重点" class="header-anchor">#</a> 2.1 数据类型（重点）</h3> <p>生活中，数据都是有类型这个概念的，比如张三18岁，18这个数字就是整型的，买了2.5斤菜，2.5就是小数类型的，在Java中每一个数据也有数据类型。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/3hwAMSQVJix5pBX.png" alt=""></em></p> <p>在计算机中，人为地把8个二进制位称为一个字节(byte)</p> <p>8大基本数据数据类型所<strong>占内存大小</strong> 和可存储的数据范围：</p> <table><thead><tr><th>No.</th> <th>数据类型</th> <th>占位(字节)</th> <th>数据范围</th></tr></thead> <tbody><tr><td>1</td> <td>byte</td> <td>1</td> <td>[ -128 , 127 ]</td></tr> <tr><td>2</td> <td>short</td> <td>2</td> <td>[ -32768 , 32767 ]</td></tr> <tr><td>3</td> <td><strong>int</strong></td> <td><strong>4</strong></td> <td>[ -2^31^ , 2^31^ - 1 ]    ≈  <b>[-21亿，21亿] </b></td></tr> <tr><td>4</td> <td>long</td> <td>8</td> <td>[ -2^63^ , 2^63^-1 ]</td></tr> <tr><td>6</td> <td>float</td> <td>4</td> <td>[-3.4x10^38^ ,   3.4x10^38^]</td></tr> <tr><td>7</td> <td><strong>double</strong></td> <td><strong>8</strong></td> <td>[-1.7x10^308^ ,  1.7x10^308^]</td></tr> <tr><td>5</td> <td>char</td> <td>2</td> <td>[0 ,  2^16^-1]</td></tr> <tr><td>8</td> <td>boolean</td> <td>1个二进制位</td> <td>true,false</td></tr></tbody></table> <pre style="color:red;">提醒：开发者需要明确记住每个具体数据类型所占字节数（内存大小）。
</pre> <p><strong>整数类型常量</strong></p> <p>在 java 中，整型常量默认使用 int 类型来存储 。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">IntTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 控制台输出10，这个10是一个常量，默认使用int存储。</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        
        <span class="token comment">// 控制台输出20，这个20如果想以long类型存储，需要加L</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">20L</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>如果要存储long类型常量，要加L或者l，建议加L。<strong>常用的整数类型是int和long</strong>，byte和short基本不用。</p> <p><strong>小数类型常量</strong></p> <p>小数类型默认是double类型，如果要存储 float 类型常量，要加f或者F。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">DoubleTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 3.14是一个小数常量，默认使用double存储。</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// float类型常量,需要加F/f后缀</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14f</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>另外，实际开发过程中，如何选择这两种数据类型呢？，看小数的位数：</p> <p>float类型精确到6-7位，double精确到15-16位，绝大部分应用程序都采用double类型。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">// float 类型只能精确到6-7</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.141592653f</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 输出3.1415927</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>注意：</p> <ul><li><strong>小数类型在计算机中存储是不精确的</strong>，所以，float，double 类型的数据不适合用在金融计算领域(不容许舍入误差)。</li></ul> <p><strong>字符类型常量</strong></p> <p>Java中的字符表示Unicode（万国码）编码表中的每一个符号，每个符号<strong>使用单引号引起来</strong>，其中前128个符号和ASCII表相同，如下图。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/GaBFbOirpfvWC4t.png" alt=""></em></p> <p>这张表要记住的几个符号，A在码表的顺序是65，a在码表的顺序是97。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CharTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 控制台输出字符A</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token char">'A'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><strong>布尔类型常量</strong></p> <p>boolean 类型只有两个值，true 和 false , 分别表示对与错，在未来的开发中用于逻辑判断。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BooleanTypeDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>字符串类型（String）常量</strong></p> <p>所谓字符串就是多个字符合在一起，使用<strong>双引号</strong>引起来。例如 : 在开发中要打印一个用户的名字就可以使用字符串了，因为一个用户的名字是由多个字符构成的。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StringDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> main <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;叩丁狼&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>提醒：先记住String表示字符串类型就可以了，后续会学习（它属于引用类型先不管）。</p> <p>需求：打印输出每一种数据类型的常量</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TypeDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// int类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// long类型常量,使用L后缀</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">20L</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// float类型常量,使用F后缀</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// double类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">3.14</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// char类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token char">'A'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// boolean类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// String类型常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;你好&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h3 id="_2-2-变量-重点"><a href="#_2-2-变量-重点" class="header-anchor">#</a> 2.2 变量（重点）</h3> <p>通过一张不完整的房屋租赁合同，引出变量 ( variable )。</p> <p>案例：张三需要租赁李四的房屋，租赁合同如下：</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/21hZTRpUEXNn7tL.png" alt=""></em></p> <p>上述合同，相当不正规，因为正规的合同上，租客和房东都是有变动的，不能写死，在整个合同中应该是使用甲方来表示房东，乙方来表示租客，只会在最后的时候签名甲方是谁，乙方是谁。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/PxNDvIMuzCtcyeE.png" alt=""></em></p> <h4 id="_2-2-1-变量概述-了解"><a href="#_2-2-1-变量概述-了解" class="header-anchor">#</a> 2.2.1 变量概述（了解）</h4> <p>变量指在程序运行过程中，值可以发生变化的量。</p> <p><strong>变量是内存中一块区域，可以往该区域存储数据，修改里面的数据，也可以获取里面的数据</strong>。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/RkhczxiIqWjd4Xf.png" alt=""></em></p> <p>变量定义的语法：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>数据类型 变量名 <span class="token operator">=</span> 初始值<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>变量的特点：</p> <ul><li>占据着内存中的某一块存储区域</li> <li>该区域有自己的名称（变量名）和大小（数据类型）</li> <li>可以被重复使用</li> <li>该区域的数据可以在同一类型范围内不断变化</li></ul> <h4 id="_2-2-2-变量定义和赋值-重点"><a href="#_2-2-2-变量定义和赋值-重点" class="header-anchor">#</a> 2.2.2 变量定义和赋值（重点）</h4> <p>需求：定义一个int类型变量，存储一个学生的年龄，并赋值17。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">VarDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 方式一: 在定义时同时赋值（推荐）</span>
        <span class="token comment">// 定义一个String类型的变量，初始值为wolf</span>
        <span class="token class-name">String</span> name <span class="token operator">=</span> <span class="token string">&quot;wolf&quot;</span><span class="token punctuation">;</span>
        
        
        <span class="token comment">// 方式二 : 定义和赋值分开写</span>
        <span class="token comment">// 1 数据类型  变量名; </span>
        <span class="token keyword">int</span> age<span class="token punctuation">;</span>   <span class="token comment">// 定义一个int类型变量</span>
        <span class="token comment">// 2 变量名 = 常量值;</span>
        age <span class="token operator">=</span> <span class="token number">17</span><span class="token punctuation">;</span>  <span class="token comment">// 给变量设置初始值为17</span>
        age <span class="token operator">=</span> <span class="token number">18</span><span class="token punctuation">;</span>  <span class="token comment">// 修改age变量的值为18</span>
        <span class="token comment">// 3 使用age变量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p><strong>使用变量注意：</strong></p> <ul><li>变量必须先定义，并且初始化后(赋上初始值)才能使用</li> <li>同一 { } 内，变量名不能重复定义</li> <li>变量从开始定义到所在的花括号结束之内可以使用，离开花括号就不能使用了</li></ul> <p>记： 语法格式</p> <ul><li>String，表示类型，这里可以写任何的类型</li> <li>name：变量名，和我们的姓名一样理解， 没有为什么</li> <li>=：赋值运算符，后面会讲，意思是将右边的值赋值给左边的变量</li> <li>&quot;wolf&quot;：一个字符串类型的值，如果是其他类型，不要加引号</li></ul> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/TJKP6DG1ROHuI9C.png" alt=""></em></p> <p>需求：定义每一种常用数据类型的变量</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">VarDemo2</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">//int类型变量</span>
		<span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">//long类型变量,使用L后缀</span>
		<span class="token keyword">long</span> l <span class="token operator">=</span> <span class="token number">20L</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>l<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">//float类型变量,使用F后缀</span>
		<span class="token keyword">float</span> f <span class="token operator">=</span> <span class="token number">3.14F</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">//double类型变量</span>
		<span class="token keyword">double</span> d <span class="token operator">=</span> <span class="token number">3.14</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">//char类型变量</span>
		<span class="token keyword">char</span> c <span class="token operator">=</span> <span class="token char">'A'</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">//boolean类型变量</span>
		<span class="token keyword">boolean</span> bool <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>bool<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">//String类型变量</span>
		<span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token string">&quot;你好&quot;</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br></div></div><p>综合案例：交换两个相同类型变量的值</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/JNXbs52HdAtjvVZ.png" alt=""></em></p> <p>1、把num1的值存储到临时变量temp中去</p> <p>2、把num2的值赋给num1变量</p> <p>3、把temp存储的值赋给num2变量</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ChangVarDemo</span><span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">int</span> num1 <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
      <span class="token keyword">int</span> num2 <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num1<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num2<span class="token punctuation">)</span><span class="token punctuation">;</span>

      <span class="token comment">// --------------------------------		</span>
      <span class="token comment">// 交换过程</span>
      <span class="token keyword">int</span> temp <span class="token operator">=</span> num1<span class="token punctuation">;</span>
      num1 <span class="token operator">=</span> num2<span class="token punctuation">;</span>
      num2 <span class="token operator">=</span> temp<span class="token punctuation">;</span>

      <span class="token comment">//--------------------------------		</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num1<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num2<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h4 id="_2-2-3-表达式"><a href="#_2-2-3-表达式" class="header-anchor">#</a> 2.2.3 表达式</h4> <p>表达式（expression），是由数字、常量、变量、运算符、括号等组合以能求得结果的式子</p> <p>作用：表达式在开发过程中用于计算结果。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/nM4Wyc3OqCHL5bQ.png" alt=""></em></p> <p>表达式举例（下列a、b、x、y、z都表示变量）。</p> <ul><li><p>a + b</p></li> <li><p>3.14 + a</p></li> <li><p>(x + y) * z + 100</p></li></ul> <h2 id="三、基本数据类型转换"><a href="#三、基本数据类型转换" class="header-anchor">#</a> 三、基本数据类型转换</h2> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/Qakf1rMvONo7gxt.png" alt=""></em></p> <p>问题：三个大小不同容器，能相互把盛装的水倒给对方吗？</p> <p>在8大基本数据类型中，boolean不属于数值类型 ( 主要用于逻辑判断 )，所以不参与转换。</p> <p>转换规则如下图：</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/ayS2wBEoFrh59NJ.png" alt=""></em></p> <p>按照转换方式，有两种：</p> <ul><li>自动类型转换：范围小的数据类型直接转换成范围大的数据类型 (小 =&gt; 大)。</li> <li>强制类型转换：范围大的数据类型<strong>强制</strong>转换成范围小的数据类型 (大 =&gt; 小)。</li></ul> <p>注意：</p> <ul><li>一般的，byte、short、char三种类型之间一般不参与转换。</li> <li><strong>float类型表示的数据范围比long大</strong></li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code>科普了解<span class="token operator">:</span>
<span class="token keyword">float</span>占<span class="token number">4</span>个字节为什么比<span class="token keyword">long</span>占<span class="token number">8</span>个字节大？<span class="token operator">--</span><span class="token operator">-&gt;</span> 因为底层的实现方式不同
<span class="token keyword">float</span>类型的<span class="token number">32</span>位并不是简单直接表示大小，而是按照一定标准分配的。
第<span class="token number">1</span>位，符号位，即<span class="token class-name">S</span>
接下来<span class="token number">8</span>位，指数域，即<span class="token class-name">E</span>。
剩下<span class="token number">23</span>位，小数域，即<span class="token class-name">M</span>，取值范围为<span class="token punctuation">[</span><span class="token number">1</span> <span class="token punctuation">,</span><span class="token number">2</span> <span class="token punctuation">)</span> 或<span class="token punctuation">[</span><span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
然后按照公式：<span class="token class-name">V</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">^</span> s <span class="token operator">*</span> <span class="token class-name">M</span> <span class="token operator">*</span> <span class="token number">2</span> <span class="token operator">^</span> <span class="token class-name">E</span>  
也就是说小数<span class="token keyword">float</span>在内存中的<span class="token number">32</span>位不是简单地转换为十进制，而是通过公式来计算而来，通过这个公式，虽然只有<span class="token number">4</span>个字节，但小数最大值要比长整型的范围要大。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="_3-1-自动类型转换-掌握"><a href="#_3-1-自动类型转换-掌握" class="header-anchor">#</a> 3.1 自动类型转换（掌握）</h3> <p>自动类型转换，也称为&quot;隐式类型转换&quot;，就是把范围小的数据类型直接转换成范围大的数据类型。</p> <p><strong>转换规则：byte、short、char—&gt;int—&gt;long—&gt;float—&gt;double</strong></p> <p>语法格式</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>范围大的数据类型 变量 <span class="token operator">=</span> 范围小的数据类型常量值<span class="token operator">/</span>变量<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>语法举例：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TypeConvertDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">int</span> intNum1 <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>			<span class="token comment">// 没有发生类型转换</span>
        <span class="token keyword">long</span> longNum2 <span class="token operator">=</span> intNum1<span class="token punctuation">;</span>	<span class="token comment">// 发生自动类型转换</span>

        <span class="token keyword">long</span> longNum3 <span class="token operator">=</span> <span class="token number">30L</span><span class="token punctuation">;</span>
        <span class="token keyword">float</span> floatNum4 <span class="token operator">=</span> longNum3<span class="token punctuation">;</span>

        <span class="token comment">// 思考: 以下代码是否正确？</span>
        <span class="token keyword">float</span> floatNum5 <span class="token operator">=</span> <span class="token number">3.14f</span><span class="token punctuation">;</span>
        <span class="token keyword">double</span> doubleNum6 <span class="token operator">=</span> floatNum5<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_3-2-自动类型提升-掌握"><a href="#_3-2-自动类型提升-掌握" class="header-anchor">#</a> 3.2 自动类型提升（掌握）</h3> <p>当一个算术表达式中，包含多个基本数据类型的常量或变量（boolean除外）时，整个算术表达式的结果类型将在出现自动提升，
其规则是：</p> <ul><li><p><strong>所有的byte、short、char类型被自动提升到int类型，再参与运算</strong></p></li> <li><p><strong>整个表达式的最终结果类型，被提升到表达式中数据范围最大的那个类型</strong></p></li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TypeConvertDemo2</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">int</span> result <span class="token operator">=</span> <span class="token char">'a'</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span> 	<span class="token comment">// 'a'转成int后是97</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">double</span> d1 <span class="token operator">=</span> <span class="token number">123</span> <span class="token operator">+</span> <span class="token number">1.1F</span> <span class="token operator">+</span> <span class="token number">3.14</span> <span class="token operator">+</span> <span class="token number">99L</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/wkuSedHbsYojX6F.png" alt=""></em></p> <p>结论：算术表达式结果的类型就是操作数中范围最大的数据类型。</p> <h3 id="_3-3-强制类型转换-掌握"><a href="#_3-3-强制类型转换-掌握" class="header-anchor">#</a> 3.3 强制类型转换（掌握）</h3> <p>强制类型转换，也称为“显式类型转换”，就是把范围大的数据类型强制转换成范围小的数据类型。</p> <p>语法格式：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>范围小的数据类型  变量 <span class="token operator">=</span> <span class="token punctuation">(</span>范围小的数据类型<span class="token punctuation">)</span>范围大的数据类型值<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>注意：一般情况下不建议使用强转，因为强转有可能损失精度</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TypeConvertDemo3</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// 强制类型转换</span>
        <span class="token keyword">float</span> floatNum1 <span class="token operator">=</span> <span class="token number">3.14f</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> intNum <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span>floatNum1<span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>intNum<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 应用:根据消费金额计算vip积分(规则：一块钱积2分)</span>
        <span class="token keyword">float</span> price <span class="token operator">=</span> <span class="token number">998.88f</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> vipScore <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span>price <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>vipScore<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 思考题:给定一个字符类型变量c，里面存了一个字符 请将它转成字母表中的下一个字符</span>
        <span class="token keyword">char</span> c <span class="token operator">=</span> <span class="token char">'a'</span><span class="token punctuation">;</span>
        <span class="token keyword">char</span> c2 <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">char</span><span class="token punctuation">)</span><span class="token punctuation">(</span>c <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c2<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h2 id="四、运算符"><a href="#四、运算符" class="header-anchor">#</a> 四、运算符</h2> <p>对常量和变量进行操作的符号称为运算符( operator )。</p> <p>常用运算符 ：</p> <ul><li><p>算术运算符</p></li> <li><p>赋值运算符</p></li> <li><p>比较运算符</p></li> <li><p>逻辑运算符</p></li> <li><p>三元运算符</p></li></ul> <h3 id="_4-1-算术运算符-掌握"><a href="#_4-1-算术运算符-掌握" class="header-anchor">#</a> 4.1 算术运算符（掌握）</h3> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/Cq1hZdrDGLVEITP.png" alt=""></em></p> <p>用来四则运算的符号，和小学学习的加减乘除无异。</p> <h4 id="_4-1-1-加减乘除余-了解"><a href="#_4-1-1-加减乘除余-了解" class="header-anchor">#</a> 4.1.1 加减乘除余（了解）</h4> <p>对于字符串而言，+符号表示连接操作，任何类型的数据和字符串相连接，结果都是字符串。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ArithOperatorDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 算术运算符 +  -  * /</span>
        <span class="token keyword">int</span> num1 <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> num2 <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> r1 <span class="token operator">=</span> num1 <span class="token operator">+</span> num2<span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>r1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        
        <span class="token comment">// 整除操作  </span>
        <span class="token keyword">int</span> num3 <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num3 <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num3 <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        
        <span class="token comment">// 字符串连接符</span>
        <span class="token keyword">int</span> num4 <span class="token operator">=</span> <span class="token number">40</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token string">&quot;num4=&quot;</span> <span class="token operator">+</span> intNum3<span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>注意：</p> <ul><li>如果/两边的操作数都是整数,/ 的结果是整数；如果/两边的操作数有一个是小数,/ 的结果是小数</li> <li>对于字符串而言，+符号表示连接操作，任何类型的数据和字符串相连接，结果都是字符串。</li></ul> <p>需求：演示取模 % 的应用</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ArithOperatorDemo2</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// % 取模(理解为求余数)</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">5</span> <span class="token operator">%</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">4</span> <span class="token operator">%</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      
        <span class="token comment">// 需求: 给定47天，问47天中有__月(30)__天</span>
        <span class="token keyword">int</span> days <span class="token operator">=</span> <span class="token number">47</span><span class="token punctuation">;</span>
        <span class="token comment">// step 1:求47天中有几个月</span>
        <span class="token keyword">int</span> month <span class="token operator">=</span> days <span class="token operator">/</span> <span class="token number">30</span><span class="token punctuation">;</span>
        <span class="token comment">// step 2:求剩余的天数 </span>
        <span class="token keyword">int</span> day <span class="token operator">=</span> days <span class="token operator">%</span> <span class="token number">30</span><span class="token punctuation">;</span>  <span class="token comment">// 47除以30后剩余的天数</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h4 id="_4-1-2-自增和自减-掌握"><a href="#_4-1-2-自增和自减-掌握" class="header-anchor">#</a> 4.1.2 自增和自减（掌握）</h4> <p>自增：++，递增操作符，使变量值增加1，有前置和后置之分，只能操作变量。</p> <p>自减：-- ，递减操作符，使变量值减去1，有前置和后置之分，只能操作变量。</p> <p>自增和自减具体操作是一样的，仅仅是一个是加1，一个是减1而已，现在单讲++。</p> <p>代码 i++和 ++i，结果都是 i 变量的值加1。</p> <p>唯一的区别是：</p> <ul><li><p>前置（++i）:  表示对result加1之后的结果进行运算</p></li> <li><p>后置（i++）:  表示对result变量加1之前的值（原始值）进行运算。</p></li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ArithOperatorDemo2</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// i++: 遇到i++，i先参与运算，运算完成后i自加1 =&gt; 速记:先使用后增加</span>
        <span class="token comment">// 情况1:</span>
        <span class="token comment">/*int i = 10;
        i++;
        System.out.println(i);*/</span>

        <span class="token comment">// 情况2:了解</span>
        <span class="token comment">/*int i = 10;
        int j = i++;
        System.out.println(i);
        System.out.println(j);*/</span>

        <span class="token comment">// ++i: 遇到++i, i先自加1，然后再参与运算</span>
        <span class="token comment">// 情况1:</span>
        <span class="token comment">/*int i = 10;
        ++i;
        System.out.println(i);*/</span>

        <span class="token comment">// 情况2:了解</span>
        <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> j <span class="token operator">=</span> <span class="token operator">++</span>i<span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>j<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><p>所以，如果仅仅执行简单的递增操作（只写i++ 或 ++i），那么选用任意一个都可以。</p> <p>总结结论：</p> <ul><li><p><strong>前置++ ：先增加后使用</strong></p></li> <li><p><strong>后置++ ：先使用后增加</strong></p></li></ul> <h3 id="_4-2-赋值运算符-掌握"><a href="#_4-2-赋值运算符-掌握" class="header-anchor">#</a> 4.2 赋值运算符（掌握）</h3> <div class="language-java line-numbers-mode"><pre class="language-java"><code>变量 <span class="token operator">=</span> 表达式的值或者常量值
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/4JdRAfInHLeEUit.png" alt=""></em></p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AssignOperatorDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// = 把等号右边的值存入等号左边的变量中，称为赋值</span>
		<span class="token keyword">int</span> age <span class="token operator">=</span> <span class="token number">17</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;age=&quot;</span> <span class="token operator">+</span> age<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
		<span class="token comment">/**
         * 变量 += n
         * 语义: 让变量自增n
         */</span>
		<span class="token keyword">int</span> num <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
        num <span class="token operator">+=</span> <span class="token number">2</span><span class="token punctuation">;</span> <span class="token comment">// 相当于 num = num + 2;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>num<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    	<span class="token comment">// 注意:+=操作已经包含了强转</span>
		<span class="token keyword">short</span> s <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
		s <span class="token operator">+=</span> <span class="token number">2</span><span class="token punctuation">;</span> <span class="token comment">// 底层相当于 s = (short) (s + 2)</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;s=&quot;</span> <span class="token operator">+</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><h3 id="_4-3-比较运算符-掌握"><a href="#_4-3-比较运算符-掌握" class="header-anchor">#</a> 4.3 比较运算符（掌握）</h3> <p>用于比较变量或常量、表达式之间的大小关系，其结果是boolean类型（要么为true，要么为false）。</p> <p>其操作格式为 :</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">boolean</span>  result  <span class="token operator">=</span> 表达式<span class="token class-name">A</span>  比较运算符  表达式<span class="token class-name">B</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/InM2UtJXZmywTND.png" alt=""></em></p> <p>注意：&gt;=符号，表示大于或者等于。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CompareOperatorDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// 直接操作常量</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&gt;</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&gt;=</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&gt;=</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&lt;</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//false</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&lt;=</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//false</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&lt;=</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">==</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">!=</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//false</span>
		
    	<span class="token comment">// 使用变量操作</span>
		<span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
		<span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
		<span class="token keyword">boolean</span> result <span class="token operator">=</span> a <span class="token operator">&gt;</span> b<span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h3 id="_4-4-三元运算符-掌握"><a href="#_4-4-三元运算符-掌握" class="header-anchor">#</a> 4.4 三元运算符（掌握）</h3> <p>三元运算符，表示有三个元素参与的运算符，所以又称为三目运算符，其语义表示：如果什么情况就做什么，否则做什么。</p> <p>语法格式：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>数据类型 变量 <span class="token operator">=</span> <span class="token keyword">boolean</span>表达式 <span class="token operator">?</span>  结果<span class="token class-name">A</span> <span class="token operator">:</span> 结果<span class="token class-name">B</span>；
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>如果boolean表达式结果：</p> <ul><li><p>为true，则三元运算符的结果是结果A；</p></li> <li><p>为false，则三元运算符的结果是结果B；</p></li></ul> <p>注：三元运算符<strong>必须定义变量接收</strong>运算的结果，否则报错。</p> <p>另外，三元运算符结果的类型由结果A和结果B来决定的，结果A和结果B的类型是相同的。</p> <p>需求1：判断一个数99是不是偶数</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TernaryOperatorDemo1</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">99</span><span class="token punctuation">;</span>
		<span class="token class-name">String</span> result <span class="token operator">=</span> a <span class="token operator">%</span> <span class="token number">2</span> <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">?</span> <span class="token string">&quot;偶数&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;奇数&quot;</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>需求2：求99和20两个数中的最大值</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TernaryOperatorDemo2</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">99</span><span class="token punctuation">;</span>
		<span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
		<span class="token keyword">int</span> result <span class="token operator">=</span> a <span class="token operator">&gt;=</span> b <span class="token operator">?</span> a <span class="token operator">:</span> b<span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;最大值：&quot;</span><span class="token operator">+</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="_4-5-逻辑运算符-掌握"><a href="#_4-5-逻辑运算符-掌握" class="header-anchor">#</a> 4.5 逻辑运算符（掌握）</h3> <p>逻辑运算符用于连接两个boolean表达式，结果也是boolean类型的。</p> <p>语法格式为：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">boolean</span>  result <span class="token operator">=</span> <span class="token keyword">boolean</span>表达式<span class="token class-name">A</span>  逻辑运算符  <span class="token keyword">boolean</span>表达式<span class="token class-name">B</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>逻辑运算符常用的有三个：</p> <ul><li>&amp;&amp; 与运算，理解为且，并且
<ul><li>运算规则：只要两边的表达式有一个为false，结果就为false（<strong>有false则false</strong>）</li></ul></li> <li>||  或运算，理解为或，或者
<ul><li>运算规则：只要两边的表达式有一个为true，结果就为true （<strong>有true则true</strong>）</li></ul></li> <li>非：取反操作
<ul><li>运算规则：!true则false , !false则true</li></ul></li></ul> <h4 id="_4-5-1-基本使用-掌握"><a href="#_4-5-1-基本使用-掌握" class="header-anchor">#</a> 4.5.1 基本使用（掌握）</h4> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LogicalOperatorDemo1</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>

		<span class="token comment">//与操作</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">false</span> <span class="token operator">&amp;&amp;</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
		
		<span class="token comment">//或操作</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token boolean">false</span> <span class="token operator">||</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
		
        <span class="token comment">//相反操作</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// false</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h4 id="_4-5-2-短路运算-掌握"><a href="#_4-5-2-短路运算-掌握" class="header-anchor">#</a> 4.5.2 短路运算（掌握）</h4> <p>&amp;&amp;：如果&amp;&amp;左边表达式为真，&amp;&amp;右边表达式参与运算；如果&amp;&amp;左边表达式为假，&amp;&amp;右边表达式不参与运算，故称短路与。</p> <p>|| :  如果||左边表达式为true，|| 右边表达式不参与运算</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LogicOperatorDemo2</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 逻辑运算符</span>
        <span class="token comment">// 短路与 &amp;&amp;</span>
        <span class="token keyword">int</span> m <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> n <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
        <span class="token comment">// boolean r1 = false &amp;&amp; true;</span>
        <span class="token keyword">boolean</span> r1 <span class="token operator">=</span> <span class="token punctuation">(</span>m <span class="token operator">&gt;</span> n<span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span><span class="token operator">++</span>m <span class="token operator">&gt;</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;r1 = &quot;</span> <span class="token operator">+</span> r1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;m = &quot;</span> <span class="token operator">+</span> m<span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token comment">// 短路或 ||</span>
        <span class="token keyword">boolean</span> r2 <span class="token operator">=</span> <span class="token punctuation">(</span>m <span class="token operator">&gt;</span> n<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token punctuation">(</span><span class="token operator">++</span>m <span class="token operator">&lt;</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;r2 = &quot;</span> <span class="token operator">+</span> r2<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_4-6-运算优先级-了解"><a href="#_4-6-运算优先级-了解" class="header-anchor">#</a> 4.6 运算优先级（了解）</h3> <p>表达式的运算都是有优先级的，基本上和数学中的优先级类似。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PriorityDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">int</span> m <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> n <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
        <span class="token comment">// 求m+n的和乘以3的结果</span>
        <span class="token keyword">int</span> r <span class="token operator">=</span> <span class="token punctuation">(</span>m <span class="token operator">+</span> n<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">3</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>运算符的优先级：</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/wf5ioYtMBbqaAlj.png" alt=""></em></p> <p>这里需要<strong>记住的结论</strong>是：</p> <ul><li><p>赋值符号最后运算的，并且是从右向左运算的，赋值运算符优先级最低</p></li> <li><p>( ) 的优先级最高，所以，开发过程中，经常通过（）来提升优先级</p></li></ul> <h2 id="五、小结与作业"><a href="#五、小结与作业" class="header-anchor">#</a> 五、小结与作业</h2> <ul><li>掌握变量的定义和赋值</li> <li>了解什么是表达式</li> <li>掌握基本数据类型的自动转换**-建议5遍**</li> <li>掌握基本数据类型的自动提升**-建议5遍**</li> <li>掌握基本数据类型的强制转换**-建议5遍**</li> <li>掌握算术运算符的使用**-建议5遍**</li> <li>前置++/--和后置++/--的区别</li> <li>掌握赋值运算符的使用，以及它的底层含义**-建议5遍**</li> <li>掌握比较运算符的使用**-建议5遍**</li> <li>掌握三元运算符的语法和使用**-建议5遍**</li> <li>掌握逻辑运算符的使用（常用 &amp;&amp; 、|| 、！）<strong>-建议5遍</strong></li> <li>了解位与（&amp;）和短路与（&amp;&amp;）的区别，记住结论使用&amp;&amp;即可</li> <li>对运算符的优先级的了解</li></ul></div></div>  <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=%E5%8F%98%E9%87%8F" title="标签">#变量</a><a href="/tags/?tag=%E8%BF%90%E7%AE%97%E7%AC%A6" title="标签">#运算符</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/32e9a2/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Java开发入门与数据类型</div></a> <a href="/pages/67fd43/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">选择语句和循环语句</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/32e9a2/" class="prev">Java开发入门与数据类型</a></span> <span class="next"><a href="/pages/67fd43/">选择语句和循环语句</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0c07b2/"><div>
            IT杂货铺
            <!----></div></a> <span class="date">03-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/705b35/"><div>
            人事百问
            <!----></div></a> <span class="date">03-22</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/78eb56/"><div>
            MyBatis-Plus
            <!----></div></a> <span class="date">03-12</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:langfeiyes@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/langfeiyes" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2024-2024
    <span><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备18007927号-1</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.a2a00aa5.js" defer></script><script src="/assets/js/2.256f807a.js" defer></script><script src="/assets/js/14.03fc6f12.js" defer></script>
  </body>
</html>
